home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / graphics / 3dvect30.arj / STARS.ASM < prev    next >
Assembly Source File  |  1993-11-18  |  10KB  |  373 lines

  1. ; display backgound stars, 1024 stars.  routine is  designed  so   only  stars
  2. ; which will be on the  screen  are  calculated.   this  is  first  done  with
  3. ; x angle indexing, then with y angle clipping, then with z distance clipping.
  4. ; this way, stars which most likely wont be visable are not rotated with those
  5. ; time-consuming IMUL's.  a mode has also been added to  make  non-perfect  3d
  6. ; stars.  this mode requires that the constants xstar  and ystar  be  adjusted
  7. ; by the user the make the stars "look" the same as perfectly calculated stars
  8. ; however, when these values are adjusted correctly, this routine is about 40%
  9. ; faster. this can be done because the stars are at a constant  distance  from
  10. ; the camera.
  11.  
  12.          .386p
  13.          jumps
  14.  
  15. code32   segment para public use32
  16.          assume cs:code32, ds:code32
  17.  
  18.          include pmode.inc       ; protected mode externals
  19.          include xmode.inc       ; include externals for xmode routines
  20.          include macros.inc
  21.          include equ.inc         ; every .asm should have access to this stuff
  22.          include 3d.inc
  23.  
  24.          include stardata.inc
  25.  
  26.          public show_stars
  27.  
  28. ; angle tolerence (lower untill stars get clipped)
  29. ;largest         equ 93  ; this is good without using z rotations in 320x400
  30. largest         equ 150 ; this is good with using z rotations in 320x400
  31.  
  32. ; this is only used when perfect_stars = yes
  33. zdistance       equ 14500 ; z clipping parameter, 16384 = all stars clipped
  34.  
  35. xstar           equ ratiox*4/128 ; these are divided by 4 to give decimals.
  36. ystar           equ ratioy*4/128 ; used when perfect_stars=no
  37.  
  38. starcolour      equ 12  ; colour for star, 1st of four (indexed from palette)
  39.  
  40. number_of_stars equ 1024         ; must be 2^some_number
  41. cut             equ 5
  42.  
  43.  
  44. ;use_half_stars equ no           ; both already defined in equ.inc
  45. ;perfect_stars  equ no           ; fast star calculation if no
  46.  
  47. smatrix       dd 6 dup (0)       ; star matrix, ematrix*xscale*yscale
  48. angle_count   dw 0
  49. starhalfpoint dw 512 ;400,600?   ; lower cutoff if use_half_stars = yes
  50.  
  51. we_is_out_of_here:
  52.          ret
  53.  
  54. show_stars:
  55.          movzx esi,eyeax         ; get camera x angle
  56.          add si,16384            ; 1/4 quadrant
  57.          shr si,5                ; 32768/2^5 = 1024
  58.  
  59.          mov ebp,esi
  60.          add bp,largest          ; sweep to bottom
  61.          sub si,largest          ; start from top
  62.  
  63.          cmp bp,number_of_stars-cut
  64.          jle s okmax
  65.          mov bp,number_of_stars-cut
  66. okmax:
  67.          cmp si,cut
  68.          jge s ok_min
  69.          mov si,cut              ; looking almost directly up
  70. ok_min:
  71.          movzx esi,xn1[esi]
  72.          movzx ebp,xn1[ebp]
  73.  
  74.          mov ax,bp
  75.          sub ax,si
  76.          shl ax,2
  77.          mov angle_count,ax
  78.  
  79.          shl si,2
  80.  
  81.         ;mov angle_count,number_of_stars
  82.         ;mov esi,0               ; uncomment this!! (along with stuff below)
  83.  
  84.          if use_half_stars eq yes
  85.          cmp si,starhalfpoint
  86.          jae s we_is_out_of_here
  87.          endif
  88.  
  89.          call set_star_matrix    ; pre-cal star matrix
  90.  
  91. more_stars:
  92.          movsx ax,sya[esi]       ; star_y_angle
  93.          neg ax
  94.          shl ax,8
  95.          sub ax,eyeay
  96.  
  97.          shr ax,8
  98.          movsx ax,al
  99.  
  100.          mov bl,tol[esi]         ; bx = tol *256
  101.          xor bh,bh
  102.          mov cx,bx
  103.  
  104.          shr cx,1
  105.          add ax,cx
  106.  
  107.          cmp ax,0                ; check left or right of screen
  108.          jl skipit
  109.  
  110.          cmp ax,bx
  111.          jg skipit               ; try removing these skipit jumps!!!
  112.  
  113.          push esi
  114.  
  115.          movsx ebx,sxl[esi]      ; star_x_location
  116.          movsx ecx,syl[esi]
  117.          movsx ebp,szl[esi]
  118.  
  119.          if perfect_stars eq yes
  120.          shl ebx,7               ; * for some accuracy
  121.          shl ecx,7
  122.          shl ebp,7
  123.  
  124.          call srotatez           ; star is eligable, calculate actual screen loc
  125.  
  126.         ;add esi,50000           ; try this too! (this is the best part)
  127.  
  128.          cmp esi,zdistance       ; clip if too close (not on apex of sphere)
  129.          jl abort_s
  130.          endif
  131.  
  132.          call srotatex           ; check tolerence in parts (saves imul's)
  133.  
  134.          if perfect_stars eq yes
  135.          mov eax,edi             ; some code from make3d routine (math.inc)
  136.          cdq
  137.          idiv esi                ; if fast mode selected, avoid idiv's
  138.          mov edi,eax
  139.          endif
  140.  
  141.          cmp di,xmins            ; draw single point/bullet
  142.          jl s abort_s
  143.          cmp di,xmaxs
  144.          jge s abort_s
  145.  
  146.          call srotatey           ; x is ok, solve for y
  147.  
  148.          if perfect_stars eq yes
  149.          mov eax,ecx
  150.          cdq
  151.          idiv ebp
  152.          mov ecx,eax
  153.          endif
  154.  
  155.          cmp cx,ymins
  156.          jl s abort_s
  157.          cmp cx,ymaxs            ; ymaxs1 if larger star (for high res screens)
  158.          jge abort_s
  159.  
  160.          mov edi, current_page   ; point to active vga page
  161.          add bx,xcent
  162.          add cx,ycent
  163.  
  164.          movzx esi,cx
  165.          shl si,1
  166.          mov ax,[esi+fastimultable] ; get offset to start of line
  167.  
  168.          mov cx, bx              ; copy to extract plane # from
  169.          shr bx, 2               ; x offset (bytes) = xpos/4
  170.          add bx, ax              ; offset = width*ypos + xpos/4
  171.  
  172.          mov ax, map_mask_plane1 ; map mask & plane select register
  173.          and cl, plane_bits      ; get plane bits
  174.          shl ah, cl              ; get plane select value
  175.          out_16 sc_index, ax     ; select plane
  176.  
  177.          pop eax                 ; select colour for star
  178.          push eax
  179.          and al,3                ; four colours
  180.          add al,starcolour
  181.  
  182.          movzx ebx,bx
  183.          mov b [edi+ebx],al      ; draw pixel, red or blue is good
  184. ;        add edi,xactual/4
  185. ;        mov [edi+ebx],16        ; draw larger bullet/pixel
  186.  
  187. ; if drawing larger star, change above code to this!
  188. ;        cmp cx,ymaxs1
  189. ;        jge s abort_s
  190. abort_s:
  191.          pop esi
  192. skipit:
  193.          if use_half_stars eq yes
  194.          cmp si,starhalfpoint
  195.          jae outhandle
  196.  
  197.          else
  198.          cmp si,number_of_stars-1-cut
  199.          jae s outhandle
  200.          endif
  201.  
  202.          inc si
  203.          dec angle_count
  204.          jnz more_stars
  205.  
  206. outhandle:
  207.          if useborders eq yes
  208.          mov ax,xmin
  209.          mov bx,xmax
  210.          mov cx,ymin
  211.          mov dx,ymax
  212.  
  213.          dec bx
  214.          dec dx
  215.  
  216.          mov lxupdate+0,ax
  217.          mov lxupdate+2,bx
  218.          mov lyupdate+0,cx
  219.          mov lyupdate+2,dx
  220.          endif
  221.  
  222.          ret
  223.  
  224. ; pre-multiply ematrix_row*constant_for_row
  225. ; to generate new matrix
  226.  
  227. ; this can be done because we don't have any
  228. ; camera location offsets (stars are at a
  229. ; fixed distance from the camera)
  230.  
  231.          align 16
  232.  
  233.          if perfect_stars eq yes
  234.  
  235. set_star_matrix:
  236.          mov ebx,ematrix+0
  237.          cmul eax,ebx,ratiox
  238.          mov smatrix+0,eax
  239.  
  240.          if usez eq yes         ; if not using z rotation, ematrix+4 =0
  241.          mov ebx,ematrix+4
  242.          cmul eax,ebx,ratiox
  243.          mov smatrix+4,eax
  244.          endif
  245.  
  246.          mov ebx,ematrix+8
  247.          cmul eax,ebx,ratiox
  248.          mov smatrix+8,eax
  249.  
  250.          mov ebx,ematrix+12
  251.          cmul eax,ebx,ratioy
  252.          mov smatrix+12,eax
  253.  
  254.          mov ebx,ematrix+16
  255.          cmul eax,ebx,ratioy
  256.          mov smatrix+16,eax
  257.  
  258.          mov ebx,ematrix+20
  259.          cmul eax,ebx,ratioy
  260.          mov smatrix+20,eax
  261.  
  262.          ret
  263.  
  264. ; if perfect_stars = no, stars will not go  through  correct  3d  calculation
  265. ; but will be calculated 40% faster. you  must  set  the  values  xstar   and
  266. ; ystar  to 3d  quick  multipliers  so  this  matrix  calculation  makes  the
  267. ; stars "look" the same.  I did this by moving the camera around and  testing
  268. ; if the stars moved the same as the objects.  I did this because the objects
  269. ; go through the correct 3d calculation and this gave me a base by  which  to
  270. ; adjust these numbers.
  271.  
  272.          else
  273.  
  274. set_star_matrix:
  275.          mov ebx,ematrix+0
  276.          cmul eax,ebx,xstar
  277.          shr eax,2
  278.          mov smatrix+0,eax
  279.  
  280.          if usez eq yes         ; if not using z rotation, ematrix+4 =0
  281.          mov ebx,ematrix+4
  282.          cmul eax,ebx,xstar
  283.          shr eax,2
  284.          mov smatrix+4,eax
  285.          endif
  286.  
  287.          mov ebx,ematrix+8
  288.          cmul eax,ebx,xstar
  289.          shr eax,2
  290.          mov smatrix+8,eax
  291.  
  292.          mov ebx,ematrix+12
  293.          cmul eax,ebx,ystar
  294.          shr eax,2
  295.          mov smatrix+12,eax
  296.  
  297.          mov ebx,ematrix+16
  298.          cmul eax,ebx,ystar
  299.          shr eax,2
  300.          mov smatrix+16,eax
  301.  
  302.          mov ebx,ematrix+20
  303.          cmul eax,ebx,ystar
  304.          shr eax,2
  305.          mov smatrix+20,eax
  306.  
  307.          ret
  308.          endif
  309.  
  310. ; rotate star using smatrix (imported from math.inc)
  311.  
  312.          align 16
  313.  
  314. srotatex:
  315.          mov eax,smatrix+8
  316.          imul ebp
  317.          shrd eax,edx,14
  318.          mov edi,eax
  319.          if usez eq yes
  320.          mov eax,smatrix+4
  321.          imul ecx
  322.          shrd eax,edx,14
  323.          add edi,eax
  324.          endif
  325.          mov eax,smatrix+0
  326.          imul ebx
  327.          shrd eax,edx,14
  328.          add edi,eax   ; di = new x
  329.          ret
  330.  
  331.          align 16
  332.  
  333. srotatey:
  334.          mov eax,smatrix+16
  335.          imul ecx
  336.          shrd eax,edx,14
  337.          mov ecx,eax
  338.          mov eax,smatrix+20
  339.          imul ebp
  340.          shrd eax,edx,14
  341.          add ecx,eax
  342.          mov eax,smatrix+12
  343.          imul ebx
  344.          shrd eax,edx,14
  345.          add ecx,eax   ; cx = new y
  346.  
  347.          mov ebp,esi
  348.          mov ebx,edi
  349.          ret
  350.  
  351.          if perfect_stars eq yes
  352.          align 16
  353.  
  354. srotatez:
  355.          mov eax,ematrix+32
  356.          imul ebp
  357.          shrd eax,edx,14
  358.          mov esi,eax
  359.          mov eax,ematrix+28
  360.          imul ecx
  361.          shrd eax,edx,14
  362.          add esi,eax
  363.          mov eax,ematrix+24
  364.          imul ebx
  365.          shrd eax,edx,14
  366.          add esi,eax   ; si = new z
  367.  
  368.          ret
  369.          endif
  370.  
  371. code32   ends
  372.          end
  373.